package gui;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;

import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;

import javax.swing.WindowConstants;

import model.basics.Instructor;
import model.basics.Request;

import org.jdesktop.application.Application;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.ListModel;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class SetInstructorWind extends javax.swing.JPanel {
	private JScrollPane instructorsPanel;
	private JLabel jLabel2;
	private JList instructorsList;
	private JButton cancelButton;
	private JButton okButton;
	private model.search.System sistem;
	private Request request;
	private JFrame frame;
	/**
	* Auto-generated main method to display this 
	* JPanel inside a new JFrame.
	*/
	public static void main(String[] args) {
		JFrame frame = new JFrame();
		frame.getContentPane().add(new SetInstructorWind());
		frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
		frame.pack();
		frame.setVisible(true);
	}
	
	public SetInstructorWind() {
		super();
		initGUI();
	}
	
	public SetInstructorWind(model.search.System sis, Request r){
		super();
		sistem = sis;
		sistem.setInstructorsList();
		request = r;
		frame = new JFrame();
		frame.getContentPane().add(this);
		frame.setPreferredSize(new Dimension(275, 335));
		frame.setTitle("Instructors");
		frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
		frame.pack();
		frame.setVisible(true);
		initGUI();
	}
	
	private void initGUI() {
		try {
			setPreferredSize(new Dimension(400, 300));
			this.setLayout(null);
			{
				instructorsPanel = new JScrollPane();
				this.add(instructorsPanel);
				instructorsPanel.setBounds(62, 47, 143, 208);
				{
					ListModel instructorsListModel = 
						new DefaultComboBoxModel(new String[] {});
					instructorsList = new JList();
					instructorsPanel.setViewportView(instructorsList);
					instructorsList.setModel(instructorsListModel);
					instructorsList.setListData(new Vector<Instructor>(sistem.getInstructorsList()));
				}
			}
			{
				jLabel2 = new JLabel();
				this.add(jLabel2);
				jLabel2.setBounds(12, 18, 235, 17);
				jLabel2.setName("jLabel2");
			}
			{
				okButton = new JButton();
				this.add(okButton);
				okButton.setBounds(44, 267, 85, 24);
				okButton.setName("okButton");
				okButton.addActionListener(new AddInstructor());
			}
			{
				cancelButton = new JButton();
				this.add(cancelButton);
				cancelButton.setBounds(140, 267, 85, 24);
				cancelButton.setName("cancelButton");
			}
			Application.getInstance().getContext().getResourceMap(getClass()).injectComponents(this);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public class AddInstructor implements ActionListener{

		public void actionPerformed(ActionEvent e) {
			// TODO Auto-generated method stub
			request.setInstructor((Instructor) instructorsList.getSelectedValue());
			frame.dispose();
		}
		
		
	}

}
